class ApplicationController < ActionController::Base
  include ExceptionLoggable
  # AuthenticatedSystem must be included for RoleRequirement, and is provided by installing acts_as_authenticates and running 'script/generate authenticated account user'.
  include AuthenticatedSystem
  # You can move this into a different controller, if you wish.  This module gives you the require_role helpers, and others.
  require 'rvideo'
  include RVideo
  include RoleRequirement
  include ApplicationHelper
  include WhiteListHelper
  # If you want "remember me" functionality, add this before_filter to Application Controller
  before_filter :login_from_cookie
  # Pick a unique cookie name to distinguish our session data from others'
  session :session_key => '_tecnophoto_session'
  
  def access_denied
    store_location
    flash[:error] = "You don't have permission to access that page."
    redirect_to :controller => '/account', :action => 'login'
  end
  
  def render_404(exception)
    respond_to do |type|
      type.html { render :template => "shared/error404", :layout => "main", :status => "404" }
      type.all  { render :nothing => true, :status => "404 Not Found" }
    end
  end

  def render_500(exception)
    respond_to do |type|
      type.html { render :template => "shared/error", :layout => "main", :status => "500" }
      type.all  { render :nothing => true, :status => "500 Error" }
    end
  end
  
  def redirect_back_or_default(default)
    if request.env["HTTP_REFERER"].nil?
      redirect_to default
    else
      redirect_to(request.env["HTTP_REFERER"]) # same as redirect_to :back
    end
  end
  
#  def local_request?
#    return false
#  end

  def pages_for(size, options = {})
    default_options = {:per_page => 15}
    options = default_options.merge options
    pages = Paginator.new self, size, options[:per_page], (params[:page]||1)
    pages
  end
end
